<template>
	<view>
		<custom-nav-sq-xcx :hasFixedFlag="hasFixedFlag" bgColor="indexNav" :needRight="true">
			<block slot="right">
				<view class="sqIndexBar posRel spaceBet" :class="[hasFixedFlag ? 'fixed' : '']" :style="{width:searchWid + 'px',height:navigationBarHeight + 'px'}">
					<view class="switchSq">
						<view class="sqName ellip">未登录</view>
						<text class="iconfont icon-sanjiao"></text>
					</view>
					<view class="scan hasFlex">
						<view class="iconfont icon-sqSaoma" @tap="goScan"></view>
						<view class="line"></view>
						<view class="iconfont icon-sqSwitch"></view>
					</view>
				</view>
			</block>
		</custom-nav-sq-xcx>
		<view class="sqHeaderImg posRel">
			<image class="samePar" :src="getStaticFilePath('sqIndex.png')"></image>
			<image class="txtImg posAbso" :src="getStaticFilePath('indexTxt.png')"></image>
		</view>
		<view class="sqIndexCon posRel">
			<tab-nav-sq
				@goSqModNav="goSqModNav"
			></tab-nav-sq>
			<image class="sqgy" :src="getStaticFilePath('sqgy.png')" @tap="goJmgy"></image>
			<!-- <view class="sqLoginTips">
				<image class="loginImg" :src="getStaticFilePath('sqNoLogin.png')"></image>
				<view>请登录APP解锁更多内容~</view>
			</view> -->
			<sq-mod-tit
				title="咨询"
				specTit="师"
				smTit="专业 便利"
				:needMore="true"
				@handleMore="goSqZxsList"
			></sq-mod-tit>
			<view class="zxsSqWrap">
				<zxs-list-sq></zxs-list-sq>
			</view>
			<sq-mod-tit
				title="社区"
				specTit="新"
				endTit="闻"
				smTit="国家时事 利民政策"
				:needMore="true"
				@handleMore="goSqNewsList"
			></sq-mod-tit>
			<view class="zxsSqWrap">
				<news-list-sq></news-list-sq>
			</view>
			<sq-mod-tit
				title="社区"
				specTit="活"
				endTit="动"
				:needMore="true"
				@handleMore="goSqHdList"
			></sq-mod-tit>
			<view class="zxsSqWrap">
				<tthd-sq></tthd-sq>
			</view>
		</view>
		<image class="sqWjgy" :src="getStaticFilePath('sqIndexGy.png')" @tap="goSqWjgy"></image>
	</view>
</template>

<script>
	import SqModTit from '@/components/sq-mod-tit'
	import TabNavSq from './components/TabNavSq'
	import ZxsListSq from './components/ZxsListSq'
	import NewsListSq from './components/NewsListSq'
	import TthdSq from './components/TthdSq'
	import { openPDFDocFile } from '@/common/openPDF.js'
	export default {
		components:{
			SqModTit,
			TabNavSq,
			ZxsListSq,
			NewsListSq,
			TthdSq
		},
		data(){
			return{
				hasFixedFlag:false,
				searchWid:getApp().globalData.menuBarLeft,
				navigationBarHeight:getApp().globalData.navigationBarHeight,
				navHeight:getApp().globalData.navHeight
			}
		},
		onPageScroll(e){
			const { scrollTop } = e;
			if(scrollTop >= this.navHeight){
				this.hasFixedFlag = true;
			}else{
				this.hasFixedFlag = false;
			}
		},
		onLoad(){
		},
		methods:{
			goScan(){
			},
			goJmgy(){
				uni.navigateTo({
					url:'/pages/subSqIndex/jmgy/jmgy'
				})
			},
			goSqZxsList(){
				uni.navigateTo({
					url:'/pages/subSqIndex/xlzx/zxsList'
				})
			},
			goSqNewsList(){
				uni.navigateTo({
					url:'/pages/subSqIndex/sqNews/sqNews'
				})
			},
			goSqHdList(){
				uni.navigateTo({
					url:'/pages/subSqIndex/tthd/tthdList'
				})
			},
			test(url){
				//let reportUrl = this.serverUrl + '/' + url;
				return new Promise((resolve,reject)=>{
					 uni.showLoading({ title: '加载中...', mask: true });
					 wx.downloadFile({
					        url,//pdf地址 例如：http://**.*****.***/ceshi/demo.pdf
					        //filePath: wx.env.USER_DATA_PATH + "/" + obj.name + ".pdf",//wx.env.USER_DATA_PATH 文件系统中的用户目录路径 filepath可有可无
					        success(res) {
								console.log(res)
					            if (res.statusCode === 200) {
									resolve(res.tempFilePath)
					    //             const tempFilePath = res.tempFilePath//返回的文件临时地址，用于后面打开本地预览所用
									// console.log(tempFilePath)
									// uni.hideLoading();
					    //             wx.openDocument({
					    //                 filePath: tempFilePath,
					    //                 showMenu: true,
					    //                 fileType: "pdf",
					    //                 success: function (res) {}
					    //             })
					            }else {
									reject('协议打开失败，请重新打开')
									//console.log('协议打开失败，请重新打开')
					                //showAutoError("协议打开失败，请重新打开");
					            }
					        },
					        fail(res) {
								reject('协议下载失败')
								//console.log('协议下载失败')
					        }
					})
				})
			},
			goSqModNav(name){
				switch(name){
					case '预约办事':
						let url = 'https://www.hxypss.com/PDF/create/2024/06/27/cp-20240627165240717.pdf';
						openPDFDocFile(url).then(res=>{
							wx.openDocument({
				                filePath: res,
				                showMenu: true,
				                fileType: "pdf",
				                success: function (res) {}
				            })
						}).catch(err=>{
							console.log(err)
						})
						// if(uni.getStorageSync('userIdPss')){
							
						// }else{
						// 	this.util.comNavigateToLogin('userFixNoRef');
						// }
						// uni.navigateTo({
						// 	url:'/pages/subSqIndex/yybs/yybs'
						// })
						
						// wx.openDocument({
						//     filePath: 'http://tmp/cWIXpGJfK8XZd19dc25dca8fc6a0200e684a8f93780b.pdf',
						//     showMenu: true,
						//     fileType: "pdf",
						//     success: function (res) {}
						// })
						//  uni.showLoading({ title: '加载中...', mask: true });
						//  wx.downloadFile({
						//         url: 'https://www.hxypss.com/PDF/create/2024/06/27/cp-20240627165240717.pdf',//pdf地址 例如：http://**.*****.***/ceshi/demo.pdf
						//         //filePath: wx.env.USER_DATA_PATH + "/" + obj.name + ".pdf",//wx.env.USER_DATA_PATH 文件系统中的用户目录路径 filepath可有可无
						//         success(res) {
						// 			console.log(res)
						//             if (res.statusCode === 200) {
						//                 const tempFilePath = res.tempFilePath//返回的文件临时地址，用于后面打开本地预览所用
						// 				console.log(tempFilePath)
						// 				uni.hideLoading();
						//                 wx.openDocument({
						//                     filePath: tempFilePath,
						//                     showMenu: true,
						//                     fileType: "pdf",
						//                     success: function (res) {}
						//                 })
						//             } else {
						// 				console.log('协议打开失败，请重新打开')
						//                 //showAutoError("协议打开失败，请重新打开");
						//             }
						//         },
						//         fail(res) {
						// 			console.log('协议下载失败')
						//         }
						// })
						
						
						break;
					case '社区概况':
						uni.navigateTo({
							url:'/pages/subSqIndex/sqGk/sqGk'
						})
						break;
					case '心理驿站':
						uni.navigateTo({
							url:'/pages/subSqIndex/xlCen/xlCen'
						})
						break;
					case '百姓论坛':
						uni.navigateTo({
							url:'/pages/subSqIndex/sqBbs/sqBbs'
						})
						break;
					case '周边配套':
						uni.navigateTo({
							url:'/pages/subSqIndex/nearPt/nearPt'
						})
						break;
					case '问卷调查':
						uni.navigateTo({
							url:'/pages/subSqIndex/sqWjdc/wjdcList'
						})
						break;
					case '意见反馈':
						uni.navigateTo({
							url:'/pages/subSqIndex/addFeedBack/addFeedBack'
						})
						break;
					case '生涯规划':
						
						break;
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	.sqIndexBar{
		align-items: center;
		color: #000;
		.switchSq{
			width: 260rpx;
			height: 100%;
			display: flex;
			margin-left: 30rpx;
			align-items: center;
			font-size: 28rpx;
			.sqName{
				max-width: 86%;
			}
			.icon-switch{
				margin-left: 5rpx;
			}
		}
		.scan{
			width: 130rpx;
			height: 50rpx;
			background: rgba(255,255,255,.4);
			margin-right: 20rpx;
			border-radius: 50rpx;
			align-items: center;
			.iconfont{
				flex: 1;
				text-align: center;
				font-size: 40rpx;
				&.icon-sqSwitch{
					font-size: 42rpx;
				}
			}
			.line{
				width: 1rpx;
				height: 26rpx;
				background: #c6a64d;
			}
		}
		&.fixed{
			color: #fff;
			.line{
				background: #fff;
			}
		}
	}
	.sqHeaderImg{
		width: 100%;
		height: 777rpx;
		z-index: 1;
		.txtImg{
			width: 364rpx;
			height: 78rpx;
			left: 30rpx;
			bottom: 230rpx;
		}
	}
	.sqIndexCon{
		padding: 40rpx 30rpx 10rpx;
		border-radius: 40rpx 40rpx 0 0;
		margin-top: -190rpx;
		z-index: 2;
		background: #fff;
		.sqgy{
			width: 690rpx;
			height: 112rpx;
			margin-bottom: 20rpx;
		}
		.zxsSqWrap{
			margin-bottom: 20rpx;
		}
	}
	.sqWjgy{
		width: 120rpx;
		height: 120rpx;
		position: fixed;
		right: 30rpx;
		bottom: 30rpx;
		z-index: 20;
	}
	.sqLoginTips{
		text-align: center;
		padding: 100rpx 0 50rpx;
		font-size: 26rpx;
		color:$sq-main0;
		.loginImg{
			width: 130rpx;
			height: 130rpx;
			margin-bottom: 10rpx;
		}
	}
</style>